package com.springcloud.feigndemoserver1000.service.impl;

import com.springcloud.common.dto.PageDTO;
import com.springcloud.common.dto.ResponseData;
import com.springcloud.common.dto.UserDTO;
import com.springcloud.common.enums.ErrorCodeEnum;
import com.springcloud.feigndemoserver1000.service.FeignUserService;
import feign.Response;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

@Component
@Slf4j
public class FeignUserServiceFallBackFactory implements FallbackFactory<FeignUserService> {
    @Override
    public FeignUserService create(Throwable throwable) {
        log.error("FeignUserService-远程调用失败！",throwable);
        return new FeignUserService() {
            @Override
            public ResponseData<UserDTO> getUserById(Integer id) {
                log.error("FeignUserServiceFallBack-getUserById-根据用户id获取用户信息失败");
                return ResponseData.response(ErrorCodeEnum.FAIL,null);
            }

            @Override
            public ResponseData<PageDTO<UserDTO>> getUserPage(PageDTO pageDTO) {
                log.error("FeignUserServiceFallBack-getUserPage-获取用户分页列表信息失败");
                return ResponseData.response(ErrorCodeEnum.FAIL,null);
            }

            @Override
            public ResponseData<?> fileUploadTest(MultipartFile file,String remark) {
                log.error("FeignUserServiceFallBack-fileUploadTest-文件上传失败");
                return  ResponseData.response(ErrorCodeEnum.FAIL,null);
            }

            @Override
            public Response imgIOStreamTest() {
                log.error("FeignUserServiceFallBack-fileUploadTest-图片流返回失败");
                return null;
            }

        };
    }
}
